Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
How to fix "Uncaught TypeError: db.collection is not a function"?

code in which the error occurs:

const countRef = db.collection('counter').doc('counter');
const increment = firebase.Firestore.FieldValue.increment(1);
const decrement = firebase.Firestore.FieldValue.increment(-1);
function change(num) {
    if (num>0) {
        countRef.update({ counter: increment });
    } else if (num<0) {
        countRef.update({ counter: decrement });
    };
};

The error is in the first line of code. I have also tried to search the internet for answers, but I have not yet found any.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As you haven't shown what db is defined to, this answer may be incorrect/not help.


The issue seems to be that you are setting db to an object which doesn't have collection().

Make sure that the db variable is defined and set to the following:

const db = firebase.firestore();

This object has the collection() method defined in it, which may fix the issue.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!